/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.si3.controlador;


import com.si3.modelo.Alumno;
import com.si3.modelo.Login;
import com.si3.modelo.Profesor;
import com.si3.modelo.Usuario;
import com.si3.servicio.LoginService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;


public class LoginController extends SimpleFormController
{
   
    
    public LoginController()
    {
        setCommandClass(Login.class);
        setCommandName("login");
        setFormView("index");
    }
    
 
    
    @Override
    protected ModelAndView onSubmit(HttpServletRequest request, 
                                    HttpServletResponse response, 
                                    Object command, 
                                    BindException errors) throws Exception 
    {
        ModelAndView mv=null;
        Login login = (Login) command;
        //login = loginService.check(login);
        
        if (login != null)
        {
        	
           if (login.getUserType() == Usuario.TipoUsuario.ALUMNO)
           {
                 
            	mv=new ModelAndView("startalumno"); 
           }
           else  if (login.getUserType() == Usuario.TipoUsuario.PROFESOR)
           {
        	   mv=new ModelAndView("startprofesor");    
        	   
           }
           else  if (login.getUserType() == Usuario.TipoUsuario.ADMIN)
           {
        	   mv=new ModelAndView("startadministrador");    
        	   
           }
           request.getSession().setAttribute("login", login);
            
        }
        return mv;
    }
    
}
